﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel.DataAnnotations;
#if NETFX_CORE
using Windows.UI.Xaml.Media.Imaging;
#else
using System.Windows.Media.Imaging;
#endif

namespace Cofe.Core.Validater
{
    /// <summary>
    /// Validate if PropertyPair's value is a valid filename.
    /// </summary>
    public class BitmapSizeAttribute : Attribute, IPropertyValidator 
    {
        public int Width { get; set; }
        public int Height { get; set; }        

        public BitmapSizeAttribute(int width, int height)
        {
            Width = width;
            Height = height;
        }

        public BitmapSizeAttribute(int width)
        {
            Width = width;
            Height = -1;
        }

        public ValidationResult GetValidationResult(object value)
        {
            if (value == null) throw new ArgumentNullException();
            if (!(value is BitmapContainer)) throw new ArgumentException();

            BitmapContainer bitmap = (value as BitmapContainer);

            if (Width != bitmap.PixelWidth || (Height != -1 && Height != bitmap.PixelHeight))
                return new ValidationResult(String.Format("Bitmap size does not match., Expected: {0}x{1}, but is: {2}x{3}", Width, Height, bitmap.PixelWidth, bitmap.PixelHeight));                
            return ValidationResult.Success;
        }
    }
}
